#include <stdio.h>
#include "list.h"
#include "list_opt.h"

int main() {
    int i = 0;
    list_t *list = new_list_node(0);

    for(i = 0; i < 15; i++){
        list = list_add(list, i + 1);
    }
    printf("初始完整链表数据\n");
    list_print(list);
    list_t *node = get_last_k_node(list, 3);  //找到倒数第3个结点
    if(node != NULL){
        printf("倒数第3个结点的值是：%d\n", node->data);
    }else{
        printf("k值不正确找不到目标结点\n");
    }

    list = convert_list(list); //翻转链表
    printf("链表翻转后的数据\n");
    list_print(list);

    list = transfer_to_ring_list(list);  //将单链表转成环形链表
    bool have_ring = is_there_a_ring(list);  //判断链表是否有环
    if(have_ring){
        printf("链表有环\n");
    }else{
        printf("链表无环\n");
    }

    printf("新建无环链表\n");
    list_t *list2 = new_list_node(20);
    for(i = 0; i < 5; i++){
        list2 = list_add(list2, i + 21);
    }
    have_ring = is_there_a_ring(list2);  //判断链表是否有环
    if(have_ring){
        printf("链表有环\n");
    }else{
        printf("链表无环\n");
    }

    return 0;
}
